package panel.viewSpots
{
	import assists.HtmlText;
	import assists.SizeManager;
	import assists.TextFieldUtils;
	import assists.resource.ResourceLoader;
	
	import flash.display.Bitmap;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.text.TextField;
	
	public class PhotoReadItem extends Sprite
	{
		private var _loader:ResourceLoader;
		private var _stage:Stage;
		private var _url:String;
		private var _descTxt:TextField;
		private var _descBackground:Shape;

		private var _bitmap:Bitmap;
		public function PhotoReadItem(loader:ResourceLoader,stage:Stage)
		{
			_loader = loader;
			_stage = stage;
			super();
			init();
		}
		
		private function init():void
		{
			_descTxt = new TextField();
			_descTxt.autoSize = "center";
			_descTxt.mouseEnabled = false;
			_descTxt.multiline = true;
			_descTxt.wordWrap = true;
			_descTxt.width = _stage.stageWidth * 0.4;
			TextFieldUtils.setHtmlText(_descTxt,HtmlText.formatSizeColor("拼了老命加载中 <br/>     请稍候...",0xffffff));
			_descTxt.x = (_stage.stageWidth - _descTxt.width) / 2;
			_descTxt.y = (_stage.stageHeight - _descTxt.height) /2;
			
			_descBackground = new Shape();
			_descBackground.graphics.beginFill(0,0.7);
			_descBackground.graphics.drawRoundRect(0,0,_descTxt.width + _stage.stageWidth * 0.01,_descTxt.height + _stage.stageHeight *0.01,_descTxt.height * 0.1);
			_descBackground.graphics.endFill();
			SizeManager.toPos(_descBackground,_descTxt);
			this.addChild(_descBackground);
			this.addChild(_descTxt);
		}
		
		public function updatePic(url:String):Boolean
		{
			if(url == _url || _bitmap == null)
				return false;
			this.removeChild(_bitmap);
			if(_loader.getImage(url) != null)
			{
				_url = url;
				loadComplete();
				return true;
			}
			return false;
		}
		
		public function loadPic(data:Object):void
		{
			_url = data.url
			_loader.loadSingleFile(_url,loadComplete);
		}
		
		private function loadComplete():void
		{
			_bitmap = _loader.getImage(_url);
			SizeManager.changeImageScale(_bitmap);
			this.addChild(_bitmap);
		}		
		
		
	}
}